<template>
  <div>
    <div class="tab-title-box">
      <span class="tab-item">我的问答</span>
    </div>
    <div class="tab-content-box">
      <div class="forum-tab-content">
        <div class="forum-content-item" v-for="item in questionList" :key="item.id">
          <div class="forum-item-title">
            <div class="community-sign" v-if="item.isTop">置顶</div>
            <div class="community-sign-essence" v-if="item.isEss">精华
            </div>
            <a @click="$router.push(`/questionDetail/${item.id}`)" class="title-text ellipsis" target="_blank">{{ item.title }}</a>
            <a v-for="tag in item.questionLabelList" :key="tag.id" class="topic-t">
              <span>#{{ tag.name }}#</span>
            </a>
          </div>
          <div class="forum-item-text">
            <div v-html="item.content"></div>
          </div>
          <div class="forum-item-info clearfix">
            <div class="forum-item-tag fl">
                    <span class="icon-box">
                      <el-icon size="20"><Comment /></el-icon>
                      {{ item.commentCount }}
                    </span>
              <span class="icon-box">
                      <el-icon size="20"><View /></el-icon>
                       {{ item.clickCount }}
                    </span>
            </div>
            <div class="forum-text-date fr">
                    <span class="info-item">
                      {{ item.user.nickName }}
                      <span> 发布于：{{ item.createTime }}</span>
                    </span>
            </div>
          </div>
        </div>
      </div>
      <div style="text-align: center; padding: 10px 0" v-if="total>10">
        <el-pagination background layout="prev, pager, next"
                       :current-page="pageNum"
                       :page-size="pageSize"
                       :total="total"
                       @update:current-page="changePageNum"
                       @current-change="getMyQuestionList"/>
      </div>
    </div>
  </div>
</template>
<script>
import { getMyQuestionList } from "@/api/u/question"
import { mapState } from "vuex";
export default {
  name: "home-center",
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      total: 0,
      questionList: []
    };
  },
  computed: {
    ...mapState({ userInfo: (state) => state.user }),
  },
  created() {
    this.getMyQuestionList()
  },
  methods: {
    changePageNum(val){
      this.pageNum = val
    },
    // 获取我的可成
    getMyQuestionList() {
      let param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      getMyQuestionList(param).then((res) => {
        this.questionList = res.data.list;
        this.total = res.data.total;
      });
    }
  },
};
</script>
<style lang="scss" scoped>
.tab-title-box {
  display: flex;
  height: 51px;
  line-height: 51px;
  border-bottom: 1px solid #e2e2e2;
  background: #ebeef5;
  .tab-item {
    margin-left: 40px;
    color: $theme-color-font;
    line-height: 51px;
    height: 52px;
    min-width: 65px;
    padding: 0 15px;
    text-align: center;
    cursor: pointer;
    font-size: 18px;
    float: left;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border-top: 2px solid $theme-color-font;
    background: #fff;
  }
}
.tab-content-box {
  background: #fff;
  padding: 0 30px;
  .forum-tab-content {
    .forum-content-item {
      width: 100%;
      border-bottom: 1px solid #ededed;
      padding: 22px 0;
      letter-spacing: normal;
      .forum-item-title {
        .community-sign {
          display: inline-block;
          width: 42px;
          height: 20px;
          line-height: 20px;
          font-size: 12px;
          font-weight: 400;
          color: #fff;
          border-radius: 10px;
          text-align: center;
          background: $theme-color-icon2;
          margin-right: 10px;
        }
        .community-sign-essence {
          display: inline-block;
          width: 42px;
          height: 20px;
          line-height: 20px;
          font-size: 12px;
          font-weight: 400;
          color: #fff;
          border-radius: 10px;
          text-align: center;
          background: $theme-color-icon;
          margin-right: 10px;
        }
        .title-text {
          font-size: 16px;
          color: #333;
          line-height: 21px;
          max-width: 450px;
          margin-right: 20px px;
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-weight: 700;
        }
        .topic-t {
          margin-left: 12px;
          line-height: 20px;
          font-size: 14px;
          font-weight: 400;
          color: #ff9e3f;
          cursor: pointer;
        }
      }
      .forum-item-text {
        font-weight: 400;
        margin: 16px 0 26px;
        color: #888;
        line-height: 22px;
        font-size: 14px;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .forum-item-info {
        .forum-item-tag {
          .icon-box {
            margin-right: 20px;
            color: #e2e2e2;
          }
        }
        .forum-text-date {
          line-height: 26px;
          color: #999;
          font-size: 12px;
        }
      }
    }
  }
}
</style>